import static org.junit.Assert.*;

import java.util.Iterator;

import org.junit.Before;
import org.junit.Test;


public class TeamManagerTest {

	TeamManager emptyToStartTeam;
	
	TeamManager threeTeam;
	HockeyPlayer x;
	HockeyPlayer y;
	HockeyPlayer z;

	@Before
	public void setUp() throws Exception {
		emptyToStartTeam = new TeamManager("Canucks");
		
		threeTeam = new TeamManager("three");
		x = new HockeyPlayer("x", "xx");
		y = new HockeyPlayer("y", "yy");
		z = new HockeyPlayer("z", "zz");
		
		threeTeam.addPlayer(x);
		threeTeam.addPlayer(y);
		threeTeam.addPlayer(z);
	}

	@Test
	public void initialized() {
		String name = emptyToStartTeam.getTeamName();
		assertTrue(name.equals("Canucks"));
		
		assertTrue(emptyToStartTeam.size() == 0);
	}
	
	@Test
	public void addOnePlayer() {
		HockeyPlayer storedPlayer = new HockeyPlayer("a", "aa");
		emptyToStartTeam.addPlayer(storedPlayer);
		
		assertTrue(emptyToStartTeam.size() == 1);
		
		HockeyPlayer fromList = emptyToStartTeam.get(0);
		assertTrue(fromList == storedPlayer);	
	}
	
	@Test
	public void addTwoPlayers() {
		HockeyPlayer storedPlayer = new HockeyPlayer("a", "aa");
		emptyToStartTeam.addPlayer(storedPlayer);

		HockeyPlayer storedPlayer2 = new HockeyPlayer("b", "bb");
		emptyToStartTeam.addPlayer(storedPlayer2);
		
		assertTrue(emptyToStartTeam.size() == 2);
		
		HockeyPlayer fromList = emptyToStartTeam.get(0);
		assertTrue(fromList == storedPlayer);	
		
		fromList = emptyToStartTeam.get(1);
		assertTrue(fromList == storedPlayer2);	
	}
	
	@Test
	public void addGoals() {
		threeTeam.addGoal(new HockeyPlayer("x", "xx"));
		
		threeTeam.addGoal(new HockeyPlayer("y", "yy"));
		threeTeam.addGoal(new HockeyPlayer("y", "yy"));
		threeTeam.addGoal(new HockeyPlayer("y", "yy"));

		
		threeTeam.addGoal(new HockeyPlayer("z", "zz"));
		threeTeam.addGoal(new HockeyPlayer("z", "zz"));

		assertTrue(threeTeam.getTotalGoalsScored() == 6);
		
		assertTrue(x.getGoals() == 1);
		assertTrue(y.getGoals() == 3);
		assertTrue(z.getGoals() == 2);

	}

	@Test
	public void orderHighestToLowest() {
		threeTeam.addGoal(new HockeyPlayer("x", "xx"));
		
		threeTeam.addGoal(new HockeyPlayer("y", "yy"));
		threeTeam.addGoal(new HockeyPlayer("y", "yy"));
		threeTeam.addGoal(new HockeyPlayer("y", "yy"));

		
		threeTeam.addGoal(new HockeyPlayer("z", "zz"));
		threeTeam.addGoal(new HockeyPlayer("z", "zz"));

		Iterator<HockeyPlayer> iter = threeTeam.iterator();
		
		HockeyPlayer mostPoints = iter.next();
		assertTrue(mostPoints == y);
		
		HockeyPlayer middlePoints = iter.next();
		assertTrue(middlePoints == z);
		
		HockeyPlayer smallestPoints = iter.next();
		assertTrue(smallestPoints == x);
		
		assertTrue(iter.hasNext() == false);
	}
}
